<html>
 <head>
  <meta charset="utf-8"/>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
  <title>
   12步轻松搞定 python 装饰器  | 数螺 | NAUT IDEA
  </title>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet"/>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
  <style type="text/css">
   #xmain img {
                  max-width: 100%;
                  display: block;
                  margin-top: 10px;
                  margin-bottom: 10px;
                }

                #xmain p {
                    line-height:150%;
                    font-size: 16px;
                    margin-top: 20px;
                }

                #xmain h2 {
                    font-size: 24px;
                }

                #xmain h3 {
                    font-size: 20px;
                }

                #xmain h4 {
                    font-size: 18px;
                }


                .header {
	           background-color: #0099ff;
	           color: #ffffff;
	           margin-bottom: 20px;
	        }

	        .header p {
                  margin: 0px;
                  padding: 10px 0;
                  display: inline-block;  
                  vertical-align: middle;
                  font-size: 16px;
               }

               .header a {
                 color: white;
               }

              .header img {
                 height: 25px;
              }
  </style>
  <script src="http://cdn.bootcss.com/jquery/3.0.0/jquery.min.js">
  </script>
  <script src="http://nautstatic-10007657.file.myqcloud.com/static/css/readability.min.js" type="text/javascript">
  </script>
  <script type="text/javascript">
   $(document).ready(function() {
                 var loc = document.location;
                 var uri = {
                  spec: "http://dataunion.org/19917.html",
                  host: "http://dataunion.org",
                  prePath: "http://dataunion.org",
                  scheme: "http",
                  pathBase: "http://dataunion.org/"
                 };
    
                 var documentClone = document.cloneNode(true);
                 var article = new Readability(uri, documentClone).parse();
     
                 document.getElementById("xmain").innerHTML = article.content;
                });
  </script>
  <!-- 1466461241: Accept with keywords: (title(0.166666666667):社区,步,python,器,数盟,装饰, topn(0.533333333333):定义,数盟,数据挖掘,查找,空间,变量名,变量,边界,嵌套,Python,调用函数,对象,例子,参数,文章,命名,排序,方法,解释器,函数,python,语法,规则,返回值,标识符,作用域,代码,函数调用,时候,装饰).-->
 </head>
 <body onload="">
  <div class="header">
   <div class="container">
    <div class="row">
     <div class="col-xs-6 col-sm-6 text-left">
      <a href="/databee">
       <img src="http://nautidea-10007657.cos.myqcloud.com/logo_white.png"/>
      </a>
      <a href="/databee">
       <p>
        数螺
       </p>
      </a>
     </div>
     <div class="hidden-xs col-sm-6 text-right">
      <p>
       致力于数据科学的推广和知识传播
      </p>
     </div>
    </div>
   </div>
  </div>
  <div class="container text-center">
   <h1>
    12步轻松搞定 python 装饰器
   </h1>
  </div>
  <div class="container" id="xmain">
   ﻿﻿
   <title>
    12步轻松搞定 python 装饰器 | 数盟社区
   </title>
   <!-- All in One SEO Pack 2.2.7.6.2 by Michael Torbert of Semper Fi Web Design[32,65] -->
   <!-- /all in one seo pack -->
   <!--
<div align="center">
<a href="http://strata.oreilly.com.cn/hadoop-big-data-cn?cmp=mp-data-confreg-home-stcn16_dataunion_pc" target="_blank"><img src="http://dataunion.org/wp-content/uploads/2016/05/stratabj.jpg"/ ></a>
</div>
-->
   <header id="header-web">
    <div class="header-main">
     <hgroup class="logo">
      <h1>
       <a href="http://dataunion.org/" rel="home" title="数盟社区">
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/logo.png"/>
       </a>
      </h1>
     </hgroup>
     <!--logo-->
     <nav class="header-nav">
      <ul class="menu" id="menu-%e4%b8%bb%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-71" id="menu-item-71">
        <a href="http://dataunion.org/category/events" title="events">
         活动
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22457" id="menu-item-22457">
          <a href="http://dataunion.org/2016timeline">
           2016档期
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22459" id="menu-item-22459">
          <a href="http://dataunion.org/category/parterc">
           合作会议
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category current-post-ancestor current-menu-parent current-post-parent menu-item-has-children menu-item-20869" id="menu-item-20869">
        <a href="http://dataunion.org/category/tech" title="articles">
         文章
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20867" id="menu-item-20867">
          <a href="http://dataunion.org/category/tech/base" title="base">
           基础架构
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3302" id="menu-item-3302">
          <a href="http://dataunion.org/category/tech/ai" title="ai">
           人工智能
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3303" id="menu-item-3303">
          <a href="http://dataunion.org/category/tech/analysis" title="analysis">
           数据分析
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21920" id="menu-item-21920">
          <a href="http://dataunion.org/category/tech/dm">
           数据挖掘
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3314" id="menu-item-3314">
          <a href="http://dataunion.org/category/tech/viz" title="viz">
           可视化
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-3305" id="menu-item-3305">
          <a href="http://dataunion.org/category/tech/devl" title="devl">
           编程语言
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-20876" id="menu-item-20876">
        <a href="http://dataunion.org/category/industry">
         行业
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-16328" id="menu-item-16328">
          <a href="http://dataunion.org/category/industry/case" title="case">
           行业应用
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-2112" id="menu-item-2112">
          <a href="http://dataunion.org/category/industry/demo" title="demo">
           Demo展示
          </a>
         </li>
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21562" id="menu-item-21562">
          <a href="http://dataunion.org/category/industry/news">
           行业资讯
          </a>
         </li>
        </ul>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-311" id="menu-item-311">
        <a href="http://dataunion.org/category/sources" title="sources">
         资源
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20870" id="menu-item-20870">
        <a href="http://dataunion.org/category/books" title="book">
         图书
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-21363" id="menu-item-21363">
        <a href="http://dataunion.org/category/training">
         课程
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-has-children menu-item-21853" id="menu-item-21853">
        <a href="http://dataunion.org/category/jobs">
         职位
        </a>
        <ul class="sub-menu">
         <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-22050" id="menu-item-22050">
          <a href="http://dataunion.org/category/career">
           职业规划
          </a>
         </li>
        </ul>
       </li>
      </ul>
     </nav>
     <!--header-nav-->
    </div>
   </header>
   <!--header-web-->
   <div id="main">
    <div id="soutab">
     <form action="http://dataunion.org/" class="search" method="get">
     </form>
    </div>
    <div id="container">
     <nav id="mbx">
      当前位置：
      <a href="http://dataunion.org">
       首页
      </a>
      &gt;
      <a href="http://dataunion.org/category/tech">
       文章
      </a>
      &gt;  正文
     </nav>
     <!--mbx-->
     <article class="content">
      <header align="centre" class="contenttitle">
       <div class="mscc">
        <h1 class="mscctitle">
         <a href="http://dataunion.org/19917.html">
          12步轻松搞定 python 装饰器
         </a>
        </h1>
        <address class="msccaddress ">
         <em>
          1,601 次阅读 -
         </em>
         <a href="http://dataunion.org/category/tech" rel="category tag">
          文章
         </a>
        </address>
       </div>
      </header>
      <div class="content-text">
       <p>
        作者：
        <a class="author-name blue-link" href="http://www.jianshu.com/users/WQXfss">
         TypingQuietly
        </a>
        出处：
        <a href="http://www.jianshu.com/p/d68c6da1587a" target="_blank">
         Wu Cheng（@nullRef）
        </a>
       </p>
       <p>
        呵呵！作为一名教python的老师，我发现学生们基本上一开始很难搞定python的装饰器，也许因为装饰器确实很难懂。搞定装饰器需要你了解一些函数式编程的概念，当然还有理解在python中定义和调用函数相关语法的一些特点。
       </p>
       <p>
        我没法让装饰器变得简单，但是通过一步步的剖析，我也许能够让你在理解装饰器的时候更自信一点。因为装饰器很复杂，这篇文章将会很长（自己都说很长，还敢这么多废话blablabla…前戏就不继续翻译直接省略了)
       </p>
       <h3>
        1. 函数
       </h3>
       <p>
        在python中，函数通过
        <code>
         def
        </code>
        关键字、函数名和可选的参数列表定义。通过
        <code>
         return
        </code>
        关键字返回值。我们举例来说明如何定义和调用一个简单的函数：
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e8aa638778722" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; def foo():
...     return 1
&amp;gt;&amp;gt;&amp;gt; foo()
1
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e8aa638778722-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8aa638778722-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8aa638778722-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8aa638778722-4">
                4
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e8aa638778722-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8aa638778722-2">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 1
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8aa638778722-3">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8aa638778722-4">
                <span class="crayon-cn">
                 1
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0015 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        方法体（当然多行也是一样的）是必须的，通过缩进来表示，在方法名的后面加上双括号
        <code>
         ()
        </code>
        就能够调用函数
       </p>
       <h3>
        2. 作用域
       </h3>
       <p>
        在python中，函数会创建一个新的作用域。python开发者可能会说函数有自己的命名空间，差不多一个意思。这意味着在函数内部碰到一个变量的时候函数会优先在自己的命名空间里面去寻找。让我们写一个简单的函数看一下
        <code>
         本地作用域
        </code>
        和
        <code>
         全局作用域
        </code>
        有什么不同：
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e8ba331254762" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; a_string = "This is a global variable"
&amp;gt;&amp;gt;&amp;gt; def foo():
...     print locals()
&amp;gt;&amp;gt;&amp;gt; print globals()
{..., 'a_string': 'This is a global variable'}
&amp;gt;&amp;gt;&amp;gt; foo() # 2
{}
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e8ba331254762-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8ba331254762-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8ba331254762-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8ba331254762-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8ba331254762-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8ba331254762-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8ba331254762-7">
                7
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e8ba331254762-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 a_string
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 "This is a global variable"
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8ba331254762-2">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8ba331254762-3">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 print
                </span>
                <span class="crayon-e">
                 locals
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8ba331254762-4">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 print
                </span>
                <span class="crayon-e">
                 globals
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8ba331254762-5">
                <span class="crayon-sy">
                 {
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 'a_string'
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 'This is a global variable'
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8ba331254762-6">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 2
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8ba331254762-7">
                <span class="crayon-sy">
                 {
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0281 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        内置的函数
        <code>
         globals
        </code>
        返回一个包含所有python解释器知道的变量名称的字典（为了干净和洗的白白的，我省略了python自行创建的一些变量）。在#2我调用了函数
        <code>
         foo
        </code>
        把函数内部
        <code>
         本地作用域
        </code>
        里面的内容打印出来。我们能够看到，函数
        <code>
         foo
        </code>
        有自己独立的命名空间，虽然暂时命名空间里面什么都还没有。
       </p>
       <h3>
        3. 变量解析规则
       </h3>
       <p>
        当然这并不是说我们在函数里面就不能访问外面的全局变量。在python的作用域规则里面，创建变量一定会一定会在当前作用域里创建一个变量，但是访问或者修改变量时会先在当前作用域查找变量，没有找到匹配变量的话会依次向上在闭合的作用域里面进行查看找。所以如果我们修改函数
        <code>
         foo
        </code>
        的实现让它打印全局的作用域里的变量也是可以的：
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e8c2864828098" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; a_string = "This is a global variable"
&amp;gt;&amp;gt;&amp;gt; def foo():
...     print a_string # 1
&amp;gt;&amp;gt;&amp;gt; foo()
This is a global variable
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e8c2864828098-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8c2864828098-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8c2864828098-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8c2864828098-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8c2864828098-5">
                5
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e8c2864828098-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 a_string
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 "This is a global variable"
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8c2864828098-2">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8c2864828098-3">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 print
                </span>
                <span class="crayon-v">
                 a_string
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 1
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8c2864828098-4">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8c2864828098-5">
                <span class="crayon-r">
                 This
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 is
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-i">
                 a
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-m">
                 global
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 variable
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0165 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        在#1处，python解释器会尝试查找变量
        <code>
         a_string
        </code>
        ，当然在函数的
        <code>
         本地作用域
        </code>
        里面是找不到的，所以接着会去上层的作用域里面去查找。
        <br/>
        但是另一方面，假如我们在函数内部给全局变量赋值，结果却和我们想的不一样：
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e8c8184289692" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; a_string = "This is a global variable"
&amp;gt;&amp;gt;&amp;gt; def foo():
...     a_string = "test" # 1
...     print locals()
&amp;gt;&amp;gt;&amp;gt; foo()
{'a_string': 'test'}
&amp;gt;&amp;gt;&amp;gt; a_string # 2
'This is a global variable'
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e8c8184289692-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8c8184289692-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8c8184289692-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8c8184289692-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8c8184289692-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8c8184289692-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8c8184289692-7">
                7
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8c8184289692-8">
                8
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e8c8184289692-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 a_string
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 "This is a global variable"
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8c8184289692-2">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8c8184289692-3">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 a_string
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 "test"
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 1
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8c8184289692-4">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 print
                </span>
                <span class="crayon-e">
                 locals
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8c8184289692-5">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8c8184289692-6">
                <span class="crayon-sy">
                 {
                </span>
                <span class="crayon-s">
                 'a_string'
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 'test'
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8c8184289692-7">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 a_string
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 2
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8c8184289692-8">
                <span class="crayon-s">
                 'This is a global variable'
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0163 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        我们能够看到，全局变量能够被访问到（如果是可变数据类型(像list,dict这些)甚至能够被更改）但是赋值不行。在函数内部的#1处，我们实际上
        <code>
         新创建
        </code>
        了一个局部变量，
        <code>
         隐藏
        </code>
        全局作用域中的同名变量。我们可以通过打印出局部命名空间中的内容得出这个结论。我们也能看到在#2处打印出来的变量
        <code>
         a_string
        </code>
        的值并没有改变。
       </p>
       <h3>
        4. 变量生存周期
       </h3>
       <p>
        值得注意的一个点是，变量不仅是生存在一个个的命名空间内，他们都有自己的生存周期，请看下面这个例子：
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e8cf596597615" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; def foo():
...     x = 1
&amp;gt;&amp;gt;&amp;gt; foo()
&amp;gt;&amp;gt;&amp;gt; print x # 1
Traceback (most recent call last):
  ...
NameError: name 'x' is not defined
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e8cf596597615-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8cf596597615-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8cf596597615-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8cf596597615-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8cf596597615-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8cf596597615-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8cf596597615-7">
                7
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e8cf596597615-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8cf596597615-2">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 1
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8cf596597615-3">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8cf596597615-4">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-i">
                 print
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 1
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8cf596597615-5">
                <span class="crayon-e">
                 Traceback
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-e">
                 most
                </span>
                <span class="crayon-e">
                 recent
                </span>
                <span class="crayon-e">
                 call
                </span>
                <span class="crayon-v">
                 last
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8cf596597615-6">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8cf596597615-7">
                <span class="crayon-v">
                 NameError
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-i">
                 name
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 'x'
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 is
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 not
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 defined
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0093 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        #1处发生的错误不仅仅是因为
        <code>
         作用域规则
        </code>
        导致的（尽管这是抛出了NameError的错误的原因）它还和python以及其它很多编程语言中函数调用实现的机制有关。在这个地方这个执行时间点并没有什么有效的语法让我们能够获取变量
        <code>
         x
        </code>
        的值，因为它这个时候压根不存在！函数
        <code>
         foo
        </code>
        的命名空间随着函数调用开始而开始，结束而销毁。
       </p>
       <h3>
        5. 函数参数
       </h3>
       <p>
        python允许我们向函数传递参数，参数会变成本地变量存在于函数内部。
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e8d6124332658" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; def foo(x):
...     print locals()
&amp;gt;&amp;gt;&amp;gt; foo(1)
{'x': 1}
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e8d6124332658-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8d6124332658-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8d6124332658-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8d6124332658-4">
                4
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e8d6124332658-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8d6124332658-2">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 print
                </span>
                <span class="crayon-e">
                 locals
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8d6124332658-3">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8d6124332658-4">
                <span class="crayon-sy">
                 {
                </span>
                <span class="crayon-s">
                 'x'
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0110 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        在Python里有很多的方式来定义和传递参数，完整版可以查看
        <a href="http://docs.python.org/tutorial/controlflow.html#more-on-defining-functions" target="_blank">
         python官方文档
        </a>
        。我们这里简略的说明一下：函数的参数可以是必须的
        <code>
         位置参数
        </code>
        或者是可选的
        <code>
         命名，默认参数
        </code>
        。
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e8dc802471731" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; def foo(x, y=0): # 1
...     return x - y
&amp;gt;&amp;gt;&amp;gt; foo(3, 1) # 2
2
&amp;gt;&amp;gt;&amp;gt; foo(3) # 3
3
&amp;gt;&amp;gt;&amp;gt; foo() # 4
Traceback (most recent call last):
  ...
TypeError: foo() takes at least 1 argument (0 given)
&amp;gt;&amp;gt;&amp;gt; foo(y=1, x=3) # 5
2
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e8dc802471731-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8dc802471731-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8dc802471731-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8dc802471731-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8dc802471731-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8dc802471731-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8dc802471731-7">
                7
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8dc802471731-8">
                8
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8dc802471731-9">
                9
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8dc802471731-10">
                10
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8dc802471731-11">
                11
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8dc802471731-12">
                12
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e8dc802471731-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 1
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8dc802471731-2">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 -
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 y
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8dc802471731-3">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-cn">
                 3
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 2
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8dc802471731-4">
                <span class="crayon-cn">
                 2
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8dc802471731-5">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-cn">
                 3
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 3
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8dc802471731-6">
                <span class="crayon-cn">
                 3
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8dc802471731-7">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 4
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8dc802471731-8">
                <span class="crayon-e">
                 Traceback
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-e">
                 most
                </span>
                <span class="crayon-e">
                 recent
                </span>
                <span class="crayon-e">
                 call
                </span>
                <span class="crayon-v">
                 last
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8dc802471731-9">
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8dc802471731-10">
                <span class="crayon-v">
                 TypeError
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 takes
                </span>
                <span class="crayon-e">
                 at
                </span>
                <span class="crayon-i">
                 least
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 argument
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 given
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8dc802471731-11">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-cn">
                 3
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 5
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8dc802471731-12">
                <span class="crayon-cn">
                 2
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0133 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        在#1处我们定义了函数
        <code>
         foo
        </code>
        ,它有一个位置参数
        <code>
         x
        </code>
        和一个命名参数
        <code>
         y
        </code>
        。在#2处我们能够通过常规的方式来调用函数，尽管有一个命名参数，但参数依然可以通过位置传递给函数。在调用函数的时候，对于命名参数
        <code>
         y
        </code>
        我们也可以完全不管就像#3处所示的一样。如果命名参数没有接收到任何值的话，python会自动使用声明的默认值也就是
        <code>
         0
        </code>
        。需要注意的是我们不能省略第一个位置参数
        <code>
         x
        </code>
        , 否则的话就会像#5处所示发生错误。
        <br/>
        目前还算简洁清晰吧， 但是接下来可能会有点令人困惑。python支持函数调用时的命名参数（个人觉得应该是命名实参）。看看#5处的函数调用，我们传递的是两个命名实参，这个时候因为有名称标识，参数传递的顺序也就不用在意了。
        <br/>
        当然相反的情况也是正确的：函数的第二个形参是
        <code>
         y
        </code>
        ，但是我们通过位置的方式传递值给它。在#2处的函数调用
        <code>
         foo(3,1)
        </code>
        ，我们把
        <code>
         3
        </code>
        传递给了第一个参数，把
        <code>
         1
        </code>
        传递给了第二个参数，尽管第二个参数是一个命名参数。
        <br/>
        桑不起，感觉用了好大一段才说清楚这么一个简单的概念：函数的参数可以有
        <code>
         名称
        </code>
        和
        <code>
         位置
        </code>
        。这意味着在函数的定义和调用的时候会稍稍在理解上有点儿不同。我们可以给只定义了位置参数的函数传递命名参数（实参），反之亦然！如果觉得不够可以查看
        <a href="https://docs.python.org/2/tutorial/controlflow.html#more-on-defining-functions" target="_blank">
         官方文档
        </a>
       </p>
       <h3>
        6. 嵌套函数
       </h3>
       <p>
        Python允许创建嵌套函数。这意味着我们可以在函数里面定义函数而且现有的作用域和变量生存周期依旧适用。
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e8e3374194285" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; def outer():
...     x = 1
...     def inner():
...         print x # 1
...     inner() # 2
...
&amp;gt;&amp;gt;&amp;gt; outer()
1
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e8e3374194285-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8e3374194285-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8e3374194285-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8e3374194285-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8e3374194285-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8e3374194285-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8e3374194285-7">
                7
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8e3374194285-8">
                8
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e8e3374194285-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 outer
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8e3374194285-2">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 1
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8e3374194285-3">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 inner
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8e3374194285-4">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-i">
                 print
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 1
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8e3374194285-5">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 inner
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 2
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8e3374194285-6">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8e3374194285-7">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 outer
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8e3374194285-8">
                <span class="crayon-cn">
                 1
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0103 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        这个例子有一点儿复杂，但是看起来也还行。想一想在#1发生了什么：python解释器需找一个叫
        <code>
         x
        </code>
        的本地变量，查找失败之后会继续在上层的作用域里面寻找，这个上层的作用域定义在另外一个函数里面。对函数
        <code>
         outer
        </code>
        来说，变量
        <code>
         x
        </code>
        是一个本地变量，但是如先前提到的一样，函数
        <code>
         inner
        </code>
        可以访问封闭的作用域（至少可以读和修改）。在#2处，我们调用函数
        <code>
         inner
        </code>
        ，非常重要的一点是，
        <code>
         inner
        </code>
        也仅仅是一个遵循python变量解析规则的变量名，python解释器会优先在
        <code>
         outer
        </code>
        的作用域里面对变量名
        <code>
         inner
        </code>
        查找匹配的变量.
       </p>
       <h3>
        7. 函数是python世界里的一级类对象
       </h3>
       <p>
        显而易见，在python里函数和其他东西一样都是对象。（此处应该大声歌唱）啊！包含变量的函数，你也并不是那么特殊！
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e8ea054351092" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; issubclass(int, object) # all objects in Python inherit from a common baseclass
True
&amp;gt;&amp;gt;&amp;gt; def foo():
...     pass
&amp;gt;&amp;gt;&amp;gt; foo.__class__ # 1
&amp;lt;type 'function'&amp;gt;
&amp;gt;&amp;gt;&amp;gt; issubclass(foo.__class__, object)
True
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e8ea054351092-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8ea054351092-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8ea054351092-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8ea054351092-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8ea054351092-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8ea054351092-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8ea054351092-7">
                7
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8ea054351092-8">
                8
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e8ea054351092-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 issubclass
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-t">
                 int
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-t">
                 object
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # all objects in Python inherit from a common baseclass
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8ea054351092-2">
                <span class="crayon-t">
                 True
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8ea054351092-3">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8ea054351092-4">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 pass
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8ea054351092-5">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 foo
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 __class__
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 1
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8ea054351092-6">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 lt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-i">
                 type
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 'function'
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8ea054351092-7">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 issubclass
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 foo
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 __class__
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-t">
                 object
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8ea054351092-8">
                <span class="crayon-t">
                 True
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0096 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        你也许从没有想过，你定义的函数居然会有属性。没办法，函数在python里面就是对象，和其他的东西一样，也许这样描述会太学院派太官方了点：在python里，函数只是一些普通的值而已和其他的值一毛一样。这就是说你尅一把函数想参数一样传递给其他的函数或者说从函数了里面返回函数！如果你从来没有这么想过，那看看下面这个例子：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e8f1939965748" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          &amp;gt;&amp;gt;&amp;gt; def add(x, y):
...     return x + y
&amp;gt;&amp;gt;&amp;gt; def sub(x, y):
...     return x - y
&amp;gt;&amp;gt;&amp;gt; def apply(func, x, y): # 1
...     return func(x, y) # 2
&amp;gt;&amp;gt;&amp;gt; apply(add, 2, 1) # 3
3
&amp;gt;&amp;gt;&amp;gt; apply(sub, 2, 1)
1
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686c2f9e8f1939965748-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8f1939965748-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686c2f9e8f1939965748-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8f1939965748-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57686c2f9e8f1939965748-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8f1939965748-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57686c2f9e8f1939965748-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8f1939965748-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57686c2f9e8f1939965748-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8f1939965748-10">
               10
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686c2f9e8f1939965748-1">
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                def
               </span>
               <span class="crayon-e">
                add
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                x
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                y
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8f1939965748-2">
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                return
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                x
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                +
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                y
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c2f9e8f1939965748-3">
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                def
               </span>
               <span class="crayon-e">
                sub
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                x
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                y
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8f1939965748-4">
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                return
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                x
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                -
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                y
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c2f9e8f1939965748-5">
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                def
               </span>
               <span class="crayon-e">
                apply
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                func
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                x
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                y
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                :
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-p">
                # 1
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8f1939965748-6">
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                return
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                func
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                x
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                y
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-p">
                # 2
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c2f9e8f1939965748-7">
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                apply
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                add
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-p">
                # 3
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8f1939965748-8">
               <span class="crayon-cn">
                3
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c2f9e8f1939965748-9">
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                apply
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-v">
                sub
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                2
               </span>
               <span class="crayon-sy">
                ,
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                1
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8f1939965748-10">
               <span class="crayon-cn">
                1
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0224 seconds] -->
       <p>
        这个例子对你来说应该不会很奇怪。
        <code>
         add
        </code>
        和
        <code>
         sub
        </code>
        是非常普通的两个python函数，接受两个值，返回一个计算后的结果值。在#1处你们能看到准备接收一个函数的变量只是一个普通的变量而已，和其他变量一样。在#2处我们调用传进来的函数：“
        <code>
         ()
        </code>
        代表着调用的操作并且调用变量包含的值。在#3处，你们也能看到传递函数并没有什么特殊的语法。” 函数的名称只是很其他变量一样的表标识符而已。
       </p>
       <p>
        你们也许看到过这样的行为：“python把频繁要用的操作变成函数作为参数进行使用，像通过传递一个函数给内置排序函数的
        <code>
         key
        </code>
        参数从而来自定义排序规则。那把函数当做返回值回事这样的情况呢：
       </p>
       <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
       <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e8f7759620745" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
        <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
         <span class="crayon-title">
         </span>
         <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-wrap-button" title="切换自动换行">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-expand-button" title="点击展开代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-copy-button" title="复制代码">
           <div class="crayon-button-icon">
           </div>
          </div>
          <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
           <div class="crayon-button-icon">
           </div>
          </div>
         </div>
        </div>
        <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
        </div>
        <div class="crayon-plain-wrap">
         <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
          &amp;gt;&amp;gt;&amp;gt; def outer():
...     def inner():
...         print "Inside inner"
...     return inner # 1
...
&amp;gt;&amp;gt;&amp;gt; foo = outer() #2
&amp;gt;&amp;gt;&amp;gt; foo
&amp;lt;function inner at 0x...&amp;gt;
&amp;gt;&amp;gt;&amp;gt; foo()
Inside inner
         </textarea>
        </div>
        <div class="crayon-main" style="">
         <table class="crayon-table">
          <tbody>
           <tr class="crayon-row">
            <td class="crayon-nums " data-settings="show">
             <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
              <div class="crayon-num" data-line="crayon-57686c2f9e8f7759620745-1">
               1
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8f7759620745-2">
               2
              </div>
              <div class="crayon-num" data-line="crayon-57686c2f9e8f7759620745-3">
               3
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8f7759620745-4">
               4
              </div>
              <div class="crayon-num" data-line="crayon-57686c2f9e8f7759620745-5">
               5
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8f7759620745-6">
               6
              </div>
              <div class="crayon-num" data-line="crayon-57686c2f9e8f7759620745-7">
               7
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8f7759620745-8">
               8
              </div>
              <div class="crayon-num" data-line="crayon-57686c2f9e8f7759620745-9">
               9
              </div>
              <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8f7759620745-10">
               10
              </div>
             </div>
            </td>
            <td class="crayon-code">
             <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
              <div class="crayon-line" id="crayon-57686c2f9e8f7759620745-1">
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                def
               </span>
               <span class="crayon-e">
                outer
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8f7759620745-2">
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                def
               </span>
               <span class="crayon-e">
                inner
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-o">
                :
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c2f9e8f7759620745-3">
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-i">
                print
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-s">
                "Inside inner"
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8f7759620745-4">
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-st">
                return
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                inner
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-p">
                # 1
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c2f9e8f7759620745-5">
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
               <span class="crayon-sy">
                .
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8f7759620745-6">
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                foo
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-o">
                =
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                outer
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-p">
                #2
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c2f9e8f7759620745-7">
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-v">
                foo
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8f7759620745-8">
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                lt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-t">
                function
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                inner
               </span>
               <span class="crayon-i">
                at
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-cn">
                0x...
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
              </div>
              <div class="crayon-line" id="crayon-57686c2f9e8f7759620745-9">
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-o">
                &amp;
               </span>
               <span class="crayon-v">
                gt
               </span>
               <span class="crayon-sy">
                ;
               </span>
               <span class="crayon-h">
               </span>
               <span class="crayon-e">
                foo
               </span>
               <span class="crayon-sy">
                (
               </span>
               <span class="crayon-sy">
                )
               </span>
              </div>
              <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8f7759620745-10">
               <span class="crayon-e">
                Inside
               </span>
               <span class="crayon-v">
                inner
               </span>
              </div>
             </div>
            </td>
           </tr>
          </tbody>
         </table>
        </div>
       </div>
       <!-- [Format Time: 0.0138 seconds] -->
       <p>
        这个例子看起来也许会更加的奇怪。在#1处我把恰好是函数标识符的变量
        <code>
         inner
        </code>
        作为返回值返回出来。这并没有什么特殊的语法：”把函数
        <code>
         inner
        </code>
        返回出来，否则它根本不可能会被调用到。“还记得变量的生存周期吗？每次函数
        <code>
         outer
        </code>
        被调用的时候，函数
        <code>
         inner
        </code>
        都会被重新定义，如果它不被当做变量返回的话，每次执行过后它将不复存在。
       </p>
       <p>
        在#2处我们捕获住返回值 – 函数
        <code>
         inner
        </code>
        ，将它存在一个新的变量
        <code>
         foo
        </code>
        里。我们能够看到，当对变量
        <code>
         foo
        </code>
        进行求值，它确实包含函数
        <code>
         inner
        </code>
        ，而且我们能够对他进行调用。初次看起来可能会觉得有点奇怪，但是理解起来并不困难是吧。坚持住，因为奇怪的转折马上就要来了（嘿嘿嘿嘿，我笑的并不猥琐！）
       </p>
       <h3>
        8. 闭包
       </h3>
       <p>
        我们先不急着定义什么是闭包，先来看看一段代码，仅仅是把上一个例子简单的调整了一下：
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e8fe395350680" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; def outer():
...     x = 1
...     def inner():
...         print x # 1
...     return inner
&amp;gt;&amp;gt;&amp;gt; foo = outer()
&amp;gt;&amp;gt;&amp;gt; foo.func_closure
(&amp;lt;cell at 0x...: int object at 0x...&amp;gt;,)
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e8fe395350680-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8fe395350680-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8fe395350680-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8fe395350680-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8fe395350680-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8fe395350680-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e8fe395350680-7">
                7
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e8fe395350680-8">
                8
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e8fe395350680-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 outer
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8fe395350680-2">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 1
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8fe395350680-3">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 inner
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8fe395350680-4">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-i">
                 print
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 1
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8fe395350680-5">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 inner
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8fe395350680-6">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 foo
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 outer
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e8fe395350680-7">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 foo
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-e">
                 func_closure
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e8fe395350680-8">
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 lt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-e">
                 cell
                </span>
                <span class="crayon-i">
                 at
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0x...
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-t">
                 int
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-t">
                 object
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-i">
                 at
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0x...
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0164 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        在上一个例子中我们了解到，
        <code>
         inner
        </code>
        作为一个函数被
        <code>
         outer
        </code>
        返回，保存在一个变量
        <code>
         foo
        </code>
        ，并且我们能够对它进行调用
        <code>
         foo()
        </code>
        。不过它会正常的运行吗？我们先来看看作用域规则。
       </p>
       <p>
        所有的东西都在python的作用域规则下进行工作：“
        <code>
         x
        </code>
        是函数
        <code>
         outer
        </code>
        里的一个局部变量。当函数
        <code>
         inner
        </code>
        在#1处打印
        <code>
         x
        </code>
        的时候，python解释器会在
        <code>
         inner
        </code>
        内部查找相应的变量，当然会找不到，所以接着会到封闭作用域里面查找，并且会找到匹配。
       </p>
       <p>
        但是从变量的生存周期来看，该怎么理解呢？我们的变量
        <code>
         x
        </code>
        是函数
        <code>
         outer
        </code>
        的一个本地变量，这意味着只有当函数
        <code>
         outer
        </code>
        正在运行的时候才会存在。根据我们已知的python运行模式，我们没法在函数
        <code>
         outer
        </code>
        返回之后继续调用函数
        <code>
         inner
        </code>
        ，在函数
        <code>
         inner
        </code>
        被调用的时候，变量
        <code>
         x
        </code>
        早已不复存在，可能会发生一个运行时错误。
       </p>
       <p>
        万万没想到，返回的函数
        <code>
         inner
        </code>
        居然能够正常工作。Python支持一个叫做
        <code>
         函数闭包
        </code>
        的特性，用人话来讲就是，嵌套定义在
        <code>
         非全局作用域
        </code>
        里面的函数能够记住它在被定义的时候它所处的封闭命名空间。这能够通过查看函数的
        <code>
         func_closure
        </code>
        属性得出结论，这个属性里面包含封闭作用域里面的值（只会包含被捕捉到的值，比如
        <code>
         x
        </code>
        ，如果在
        <code>
         outer
        </code>
        里面还定义了其他的值，封闭作用域里面是不会有的）
       </p>
       <p>
        记住，每次函数
        <code>
         outer
        </code>
        被调用的时候，函数
        <code>
         inner
        </code>
        都会被重新定义。现在变量
        <code>
         x
        </code>
        的值不会变化，所以每次返回的函数
        <code>
         inner
        </code>
        会是同样的逻辑，假如我们稍微改动一下呢？
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e905519196802" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; def outer(x):
...     def inner():
...         print x # 1
...     return inner
&amp;gt;&amp;gt;&amp;gt; print1 = outer(1)
&amp;gt;&amp;gt;&amp;gt; print2 = outer(2)
&amp;gt;&amp;gt;&amp;gt; print1()
1
&amp;gt;&amp;gt;&amp;gt; print2()
2
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e905519196802-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e905519196802-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e905519196802-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e905519196802-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e905519196802-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e905519196802-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e905519196802-7">
                7
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e905519196802-8">
                8
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e905519196802-9">
                9
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e905519196802-10">
                10
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e905519196802-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 outer
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e905519196802-2">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 inner
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e905519196802-3">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-i">
                 print
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 1
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e905519196802-4">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 inner
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e905519196802-5">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 print1
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 outer
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e905519196802-6">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 print2
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 outer
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-cn">
                 2
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e905519196802-7">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 print1
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e905519196802-8">
                <span class="crayon-cn">
                 1
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e905519196802-9">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 print2
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e905519196802-10">
                <span class="crayon-cn">
                 2
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0221 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        从这个例子中你能够看到
        <code>
         闭包
        </code>
        – 被函数记住的封闭作用域 – 能够被用来创建自定义的函数，本质上来说是一个
        <code>
         硬编码的参数
        </code>
        。事实上我们并不是传递参数
        <code>
         1
        </code>
        或者
        <code>
         2
        </code>
        给函数
        <code>
         inner
        </code>
        ，我们实际上是创建了能够打印各种数字的各种自定义版本。
       </p>
       <p>
        闭包单独拿出来就是一个非常强大的功能， 在某些方面，你也许会把它当做一个类似于面向对象的技术：
        <code>
         outer
        </code>
        像是给
        <code>
         inner
        </code>
        服务的构造器，
        <code>
         x
        </code>
        像一个私有变量。使用闭包的方式也有很多：你如果熟悉python内置排序方法的参数
        <code>
         key
        </code>
        ，你说不定已经写过一个
        <code>
         lambda
        </code>
        方法在排序一个列表的列表的时候基于第二个元素而不是第一个。现在你说不定也可以写一个
        <code>
         itemgetter
        </code>
        方法，接收一个索引值来返回一个完美的函数，传递给排序函数的参数
        <code>
         key
        </code>
        。
       </p>
       <p>
        不过，我们现在不会用闭包做这么low的事(⊙o⊙)…！相反，
        <code>
         让我们再爽一次
        </code>
        ，写一个高大上的
        <code>
         装饰器
        </code>
        !
       </p>
       <h3>
        9. 装饰器
       </h3>
       <p>
        装饰器其实就是一个闭包，把一个函数当做参数然后返回一个替代版函数。我们一步步从简到繁来瞅瞅：
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e90c305953720" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; def outer(some_func):
...     def inner():
...         print "before some_func"
...         ret = some_func() # 1
...         return ret + 1
...     return inner
&amp;gt;&amp;gt;&amp;gt; def foo():
...     return 1
&amp;gt;&amp;gt;&amp;gt; decorated = outer(foo) # 2
&amp;gt;&amp;gt;&amp;gt; decorated()
before some_func
2
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e90c305953720-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e90c305953720-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e90c305953720-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e90c305953720-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e90c305953720-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e90c305953720-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e90c305953720-7">
                7
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e90c305953720-8">
                8
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e90c305953720-9">
                9
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e90c305953720-10">
                10
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e90c305953720-11">
                11
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e90c305953720-12">
                12
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e90c305953720-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 outer
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 some_func
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e90c305953720-2">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 inner
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e90c305953720-3">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-i">
                 print
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 "before some_func"
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e90c305953720-4">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 ret
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 some_func
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 1
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e90c305953720-5">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 ret
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 +
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 1
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e90c305953720-6">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 inner
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e90c305953720-7">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e90c305953720-8">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 1
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e90c305953720-9">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 decorated
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 outer
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 foo
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 2
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e90c305953720-10">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 decorated
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e90c305953720-11">
                <span class="crayon-e">
                 before
                </span>
                <span class="crayon-v">
                 some
                </span>
                <span class="crayon-sy">
                 _
                </span>
                func
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e90c305953720-12">
                <span class="crayon-cn">
                 2
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0148 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        仔细看看上面这个装饰器的例子。们定义了一个函数
        <code>
         outer
        </code>
        ，它只有一个
        <code>
         some_func
        </code>
        的参数，在他里面我们定义了一个嵌套的函数
        <code>
         inner
        </code>
        。
        <code>
         inner
        </code>
        会打印一串字符串，然后调用
        <code>
         some_func
        </code>
        ，在#1处得到它的返回值。在
        <code>
         outer
        </code>
        每次调用的时候
        <code>
         some_func
        </code>
        的值可能会不一样，但是不管
        <code>
         some_func
        </code>
        的之如何，我们都会调用它。最后，
        <code>
         inner
        </code>
        返回
        <code>
         some_func() + 1
        </code>
        的值 – 我们通过调用在#2处存储在变量
        <code>
         decorated
        </code>
        里面的函数能够看到被打印出来的字符串以及返回值
        <code>
         2
        </code>
        ，而不是期望中调用函数
        <code>
         foo
        </code>
        得到的返回值
        <code>
         1
        </code>
        。
        <br/>
        我们可以认为变量
        <code>
         decorated
        </code>
        是函数
        <code>
         foo
        </code>
        的一个装饰版本，一个加强版本。事实上如果打算写一个有用的装饰器的话，我们可能会想愿意用装饰版本完全取代原先的函数
        <code>
         foo
        </code>
        ，这样我们总是会得到我们的”加强版“
        <code>
         foo
        </code>
        。想要达到这个效果，完全不需要学习新的语法，简单地赋值给变量
        <code>
         foo
        </code>
        就行了：
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e913731736325" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; foo = outer(foo)
&amp;gt;&amp;gt;&amp;gt; foo # doctest: +ELLIPSIS
&amp;lt;function inner at 0x...&amp;gt;
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e913731736325-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e913731736325-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e913731736325-3">
                3
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e913731736325-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 foo
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 outer
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 foo
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e913731736325-2">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 foo
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # doctest: +ELLIPSIS
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e913731736325-3">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 lt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-t">
                 function
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 inner
                </span>
                <span class="crayon-i">
                 at
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0x...
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0101 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        现在，任何怎么调用都不会牵扯到原先的函数
        <code>
         foo
        </code>
        ，都会得到新的装饰版本的
        <code>
         foo
        </code>
        ，现在我们还是来写一个有用的装饰器。
        <br/>
        想象我们有一个库，这个库能够提供类似坐标的对象，也许它们仅仅是一些x和y的坐标对。不过可惜的是这些坐标对象不支持数学运算符，而且我们也不能对源代码进行修改，因此也就不能直接加入运算符的支持。我们将会做一系列的数学运算，所以我们想要能够对两个坐标对象进行合适加减运算的函数，这些方法很容易就能写出：
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e91a627347822" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; class Coordinate(object):
...     def __init__(self, x, y):
...         self.x = x
...         self.y = y
...     def __repr__(self):
...         return "Coord: " + str(self.__dict__)
&amp;gt;&amp;gt;&amp;gt; def add(a, b):
...     return Coordinate(a.x + b.x, a.y + b.y)
&amp;gt;&amp;gt;&amp;gt; def sub(a, b):
...     return Coordinate(a.x - b.x, a.y - b.y)
&amp;gt;&amp;gt;&amp;gt; one = Coordinate(100, 200)
&amp;gt;&amp;gt;&amp;gt; two = Coordinate(300, 200)
&amp;gt;&amp;gt;&amp;gt; add(one, two)
Coord: {'y': 400, 'x': 400}
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e91a627347822-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e91a627347822-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e91a627347822-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e91a627347822-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e91a627347822-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e91a627347822-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e91a627347822-7">
                7
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e91a627347822-8">
                8
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e91a627347822-9">
                9
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e91a627347822-10">
                10
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e91a627347822-11">
                11
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e91a627347822-12">
                12
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e91a627347822-13">
                13
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e91a627347822-14">
                14
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e91a627347822-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-t">
                 class
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 Coordinate
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-t">
                 object
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e91a627347822-2">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 __init__
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-r">
                 self
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e91a627347822-3">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-r">
                 self
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-i">
                 x
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e91a627347822-4">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-r">
                 self
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-i">
                 y
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e91a627347822-5">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 __repr__
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-r">
                 self
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e91a627347822-6">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 "Coord: "
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 +
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 str
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-r">
                 self
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 __dict__
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e91a627347822-7">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 add
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 a
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 b
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e91a627347822-8">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 Coordinate
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 a
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 +
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 b
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 a
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 +
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 b
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e91a627347822-9">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 sub
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 a
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 b
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e91a627347822-10">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 Coordinate
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 a
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 -
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 b
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 a
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 -
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 b
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e91a627347822-11">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 one
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 Coordinate
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-cn">
                 100
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 200
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e91a627347822-12">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 two
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 Coordinate
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-cn">
                 300
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 200
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e91a627347822-13">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 add
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 one
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 two
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e91a627347822-14">
                <span class="crayon-v">
                 Coord
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
                <span class="crayon-s">
                 'y'
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 400
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 'x'
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 400
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0252 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        如果不巧我们的加减函数同时也需要一些边界检查的行为那该怎么办呢？搞不好你只能够对正的坐标对象进行加减操作，任何返回的值也都应该是正的坐标。所以现在的期望是这样：
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e920923519613" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; one = Coordinate(100, 200)
&amp;gt;&amp;gt;&amp;gt; two = Coordinate(300, 200)
&amp;gt;&amp;gt;&amp;gt; three = Coordinate(-100, -100)
&amp;gt;&amp;gt;&amp;gt; sub(one, two)
Coord: {'y': 0, 'x': -200}
&amp;gt;&amp;gt;&amp;gt; add(one, three)
Coord: {'y': 100, 'x': 0}
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e920923519613-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e920923519613-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e920923519613-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e920923519613-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e920923519613-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e920923519613-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e920923519613-7">
                7
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e920923519613-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 one
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 Coordinate
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-cn">
                 100
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 200
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e920923519613-2">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 two
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 Coordinate
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-cn">
                 300
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 200
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e920923519613-3">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 three
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 Coordinate
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-o">
                 -
                </span>
                <span class="crayon-cn">
                 100
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 -
                </span>
                <span class="crayon-cn">
                 100
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e920923519613-4">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 sub
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 one
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 two
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e920923519613-5">
                <span class="crayon-v">
                 Coord
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
                <span class="crayon-s">
                 'y'
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 'x'
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 -
                </span>
                <span class="crayon-cn">
                 200
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e920923519613-6">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 add
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 one
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 three
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e920923519613-7">
                <span class="crayon-v">
                 Coord
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
                <span class="crayon-s">
                 'y'
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 100
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 'x'
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0129 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        我们期望在不更改坐标对象
        <code>
         one, two, three
        </code>
        的前提下
        <code>
         one
        </code>
        减去
        <code>
         two
        </code>
        的值是
        <code>
         {x: 0, y: 0}
        </code>
        ，
        <code>
         one
        </code>
        加上
        <code>
         three
        </code>
        的值是
        <code>
         {x: 100, y: 200}
        </code>
        。与其给每个方法都加上参数和返回值边界检查的逻辑，我们来写一个边界检查的装饰器！
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e926851708690" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; def wrapper(func):
...     def checker(a, b): # 1
...         if a.x &amp;lt; 0 or a.y &amp;lt; 0:
...             a = Coordinate(a.x if a.x &amp;gt; 0 else 0, a.y if a.y &amp;gt; 0 else 0)
...         if b.x &amp;lt; 0 or b.y &amp;lt; 0:
...             b = Coordinate(b.x if b.x &amp;gt; 0 else 0, b.y if b.y &amp;gt; 0 else 0)
...         ret = func(a, b)
...         if ret.x &amp;lt; 0 or ret.y &amp;lt; 0:
...             ret = Coordinate(ret.x if ret.x &amp;gt; 0 else 0, ret.y if ret.y &amp;gt; 0 else 0)
...         return ret
...     return checker
&amp;gt;&amp;gt;&amp;gt; add = wrapper(add)
&amp;gt;&amp;gt;&amp;gt; sub = wrapper(sub)
&amp;gt;&amp;gt;&amp;gt; sub(one, two)
Coord: {'y': 0, 'x': 0}
&amp;gt;&amp;gt;&amp;gt; add(one, three)
Coord: {'y': 200, 'x': 100}
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e926851708690-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e926851708690-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e926851708690-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e926851708690-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e926851708690-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e926851708690-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e926851708690-7">
                7
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e926851708690-8">
                8
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e926851708690-9">
                9
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e926851708690-10">
                10
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e926851708690-11">
                11
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e926851708690-12">
                12
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e926851708690-13">
                13
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e926851708690-14">
                14
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e926851708690-15">
                15
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e926851708690-16">
                16
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e926851708690-17">
                17
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e926851708690-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 wrapper
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 func
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e926851708690-2">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 checker
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 a
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 b
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 1
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e926851708690-3">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 if
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 a
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 lt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 or
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 a
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 lt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e926851708690-4">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 a
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 Coordinate
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 a
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-i">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 if
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 a
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 else
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 a
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-i">
                 y
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 if
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 a
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 else
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e926851708690-5">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 if
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 b
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 lt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 or
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 b
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 lt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e926851708690-6">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 b
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 Coordinate
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 b
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-i">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 if
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 b
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 else
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 b
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-i">
                 y
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 if
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 b
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 else
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e926851708690-7">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 ret
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 func
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 a
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 b
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e926851708690-8">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 if
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 ret
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 lt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 or
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 ret
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 lt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e926851708690-9">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 ret
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 Coordinate
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 ret
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-i">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 if
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 ret
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 else
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 ret
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-i">
                 y
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 if
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 ret
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 else
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e926851708690-10">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-i">
                 ret
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e926851708690-11">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 checker
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e926851708690-12">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 add
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 wrapper
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 add
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e926851708690-13">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 sub
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 wrapper
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 sub
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e926851708690-14">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 sub
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 one
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 two
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e926851708690-15">
                <span class="crayon-v">
                 Coord
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
                <span class="crayon-s">
                 'y'
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 'x'
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e926851708690-16">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 add
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 one
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 three
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e926851708690-17">
                <span class="crayon-v">
                 Coord
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
                <span class="crayon-s">
                 'y'
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 200
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 'x'
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 100
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0262 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        这个装饰器能想先前的装饰器例子一样进行工作，返回一个经过修改的函数，但是在这个例子中，它能够对函数的输入参数和返回值做一些非常有用的检查和格式化工作，将负值的
        <code>
         x
        </code>
        和
        <code>
         y
        </code>
        替换成
        <code>
         0
        </code>
        。
        <br/>
        显而易见，通过这样的方式，我们的代码变得更加简洁：将边界检查的逻辑隔离到单独的方法中，然后通过装饰器包装的方式应用到我们需要进行检查的地方。另外一种方式通过在计算方法的开始处和返回值之前调用边界检查的方法也能够达到同样的目的。但是不可置否的是，使用装饰器能够让我们以最少的代码量达到坐标边界检查的目的。事实上，如果我们是在装饰自己定义的方法的话，我们能够让装饰器应用的更加有逼格。
       </p>
       <h3>
        10. 使用
        <strong>
         @
        </strong>
        标识符将装饰器应用到函数
       </h3>
       <p>
        Python2.4支持使用标识符
        <code>
         @
        </code>
        将装饰器应用在函数上，只需要在函数的定义前加上
        <code>
         @
        </code>
        和装饰器的名称。在上一节的例子里我们是将原本的方法用装饰后的方法代替:
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e92d607256164" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; add = wrapper(add)
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e92d607256164-1">
                1
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e92d607256164-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 add
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 wrapper
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 add
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0012 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        这种方式能够在任何时候对任意方法进行包装。但是如果我们自定义一个方法，我们可以使用
        <code>
         @
        </code>
        进行装饰：
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e933316112177" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; @wrapper
... def add(a, b):
...     return Coordinate(a.x + b.x, a.y + b.y)
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e933316112177-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e933316112177-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e933316112177-3">
                3
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e933316112177-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 @
                </span>
                <span class="crayon-i">
                 wrapper
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e933316112177-2">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 add
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 a
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 b
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e933316112177-3">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 Coordinate
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 a
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 +
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 b
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 a
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 +
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 b
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0081 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        需要明白的是，这样的做法和先前简单的用包装方法替代原有方法是一毛一样的， python只是加了一些语法糖让装饰的行为更加的直接明确和优雅一点。
       </p>
       <h3>
        11. *args and **kwargs
       </h3>
       <p>
        我们已经完成了一个有用的装饰器，但是由于硬编码的原因它只能应用在一类具体的方法上，这类方法接收两个参数，传递给闭包捕获的函数。如果我们想实现一个能够应用在任何方法上的装饰器要怎么做呢？再比如，如果我们要实现一个能应用在任何方法上的类似于计数器的装饰器，不需要改变原有方法的任何逻辑。这意味着装饰器能够接受拥有任何签名的函数作为自己的被装饰方法，同时能够用传递给它的参数对被装饰的方法进行调用。
        <br/>
        非常巧合的是Python正好有支持这个特性的语法。可以阅读
        <a href="https://docs.python.org/2/tutorial/controlflow.html#arbitrary-argument-lists" target="_blank">
         Python Tutorial
        </a>
        获取更多的细节。当定义函数的时候使用了
        <code>
         *
        </code>
        ，意味着那些通过位置传递的参数将会被放在带有
        <code>
         *
        </code>
        前缀的变量中， 所以：
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e93a271519816" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; def one(*args):
...     print args # 1
&amp;gt;&amp;gt;&amp;gt; one()
()
&amp;gt;&amp;gt;&amp;gt; one(1, 2, 3)
(1, 2, 3)
&amp;gt;&amp;gt;&amp;gt; def two(x, y, *args): # 2
...     print x, y, args
&amp;gt;&amp;gt;&amp;gt; two('a', 'b', 'c')
a b ('c',)
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e93a271519816-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e93a271519816-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e93a271519816-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e93a271519816-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e93a271519816-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e93a271519816-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e93a271519816-7">
                7
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e93a271519816-8">
                8
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e93a271519816-9">
                9
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e93a271519816-10">
                10
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e93a271519816-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 one
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-o">
                 *
                </span>
                <span class="crayon-v">
                 args
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e93a271519816-2">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 print
                </span>
                <span class="crayon-v">
                 args
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 1
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e93a271519816-3">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 one
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e93a271519816-4">
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e93a271519816-5">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 one
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 2
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 3
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e93a271519816-6">
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 2
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 3
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e93a271519816-7">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 two
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 *
                </span>
                <span class="crayon-v">
                 args
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 2
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e93a271519816-8">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-i">
                 print
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 args
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e93a271519816-9">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 two
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-s">
                 'a'
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 'b'
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 'c'
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e93a271519816-10">
                <span class="crayon-i">
                 a
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 b
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-s">
                 'c'
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0126 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        第一个函数
        <code>
         one
        </code>
        只是简单地讲任何传递过来的位置参数全部打印出来而已，你们能够看到，在代码#1处我们只是引用了函数内的变量
        <code>
         args
        </code>
        ,
        <code>
         *args
        </code>
        仅仅只是用在函数定义的时候用来表示位置参数应该存储在变量
        <code>
         args
        </code>
        里面。Python允许我们制定一些参数并且通过
        <code>
         args
        </code>
        捕获其他所有剩余的未被捕捉的位置参数，就像#2处所示的那样。
        <br/>
        <code>
         *
        </code>
        操作符在函数被调用的时候也能使用。意义基本是一样的。当调用一个函数的时候，一个用
        <code>
         *
        </code>
        标志的变量意思是变量里面的内容需要被提取出来然后当做位置参数被使用。同样的，来看个例子：
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e941200091924" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; def add(x, y):
...     return x + y
&amp;gt;&amp;gt;&amp;gt; lst = [1,2]
&amp;gt;&amp;gt;&amp;gt; add(lst[0], lst[1]) # 1
3
&amp;gt;&amp;gt;&amp;gt; add(*lst) # 2
3
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e941200091924-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e941200091924-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e941200091924-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e941200091924-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e941200091924-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e941200091924-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e941200091924-7">
                7
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e941200091924-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 add
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e941200091924-2">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 +
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 y
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e941200091924-3">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 lst
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 [
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-cn">
                 2
                </span>
                <span class="crayon-sy">
                 ]
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e941200091924-4">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 add
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 lst
                </span>
                <span class="crayon-sy">
                 [
                </span>
                <span class="crayon-cn">
                 0
                </span>
                <span class="crayon-sy">
                 ]
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 lst
                </span>
                <span class="crayon-sy">
                 [
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-sy">
                 ]
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 1
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e941200091924-5">
                <span class="crayon-cn">
                 3
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e941200091924-6">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 add
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-o">
                 *
                </span>
                <span class="crayon-v">
                 lst
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 # 2
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e941200091924-7">
                <span class="crayon-cn">
                 3
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0107 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        #1处的代码和#2处的代码所做的事情其实是一样的，在#2处，python为我们所做的事其实也可以手动完成。这也不是什么坏事，
        <code>
         *args
        </code>
        要么是表示调用方法大的时候额外的参数可以从一个可迭代列表中取得，要么就是定义方法的时候标志这个方法能够接受任意的位置参数。
        <br/>
        接下来提到的
        <code>
         **
        </code>
        会稍多更复杂一点，
        <code>
         **
        </code>
        代表着键值对的餐宿字典，和
        <code>
         *
        </code>
        所代表的意义相差无几，也很简单对不对：
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e947924617691" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; def foo(**kwargs):
...     print kwargs
&amp;gt;&amp;gt;&amp;gt; foo()
{}
&amp;gt;&amp;gt;&amp;gt; foo(x=1, y=2)
{'y': 2, 'x': 1}
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e947924617691-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e947924617691-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e947924617691-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e947924617691-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e947924617691-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e947924617691-6">
                6
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e947924617691-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-o">
                 *
                </span>
                <span class="crayon-o">
                 *
                </span>
                <span class="crayon-v">
                 kwargs
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e947924617691-2">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 print
                </span>
                <span class="crayon-v">
                 kwargs
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e947924617691-3">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e947924617691-4">
                <span class="crayon-sy">
                 {
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e947924617691-5">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 foo
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-cn">
                 2
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e947924617691-6">
                <span class="crayon-sy">
                 {
                </span>
                <span class="crayon-s">
                 'y'
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 2
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 'x'
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0108 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        当我们定义一个函数的时候，我们能够用
        <code>
         **kwargs
        </code>
        来表明，所有未被捕获的关键字参数都应该存储在
        <code>
         kwargs
        </code>
        的字典中。如前所诉，
        <code>
         args
        </code>
        he
        <code>
         kwargs
        </code>
        并不是python语法的一部分，但在定义函数的时候，使用这样的变量名算是一个不成文的约定。和
        <code>
         *
        </code>
        一样，我们同样可以在定义或者调用函数的时候使用
        <code>
         **
        </code>
        。
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e94d568133348" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; dct = {'x': 1, 'y': 2}
&amp;gt;&amp;gt;&amp;gt; def bar(x, y):
...     return x + y
&amp;gt;&amp;gt;&amp;gt; bar(**dct)
3
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e94d568133348-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e94d568133348-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e94d568133348-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e94d568133348-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e94d568133348-5">
                5
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e94d568133348-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 dct
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
                <span class="crayon-s">
                 'x'
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 'y'
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 2
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e94d568133348-2">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 bar
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e94d568133348-3">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 +
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 y
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e94d568133348-4">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 bar
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-o">
                 *
                </span>
                <span class="crayon-o">
                 *
                </span>
                <span class="crayon-v">
                 dct
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e94d568133348-5">
                <span class="crayon-cn">
                 3
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0096 seconds] -->
        <p>
        </p>
       </blockquote>
       <h3>
        12. 更通用的装饰器
       </h3>
       <p>
        有了这招新的技能，我们随随便便就可以写一个能够记录下传递给函数参数的装饰器了。先来个简单地把日志输出到界面的例子：
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e953012523635" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; def logger(func):
...     def inner(*args, **kwargs): #1
...         print "Arguments were: %s, %s" % (args, kwargs)
...         return func(*args, **kwargs) #2
...     return inner
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e953012523635-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e953012523635-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e953012523635-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e953012523635-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e953012523635-5">
                5
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e953012523635-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 logger
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 func
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e953012523635-2">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 inner
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-o">
                 *
                </span>
                <span class="crayon-v">
                 args
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 *
                </span>
                <span class="crayon-o">
                 *
                </span>
                <span class="crayon-v">
                 kwargs
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 #1
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e953012523635-3">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-i">
                 print
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-s">
                 "Arguments were: %s, %s"
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 %
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 args
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 kwargs
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e953012523635-4">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 func
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-o">
                 *
                </span>
                <span class="crayon-v">
                 args
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-o">
                 *
                </span>
                <span class="crayon-o">
                 *
                </span>
                <span class="crayon-v">
                 kwargs
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-p">
                 #2
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e953012523635-5">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 inner
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0201 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        请注意我们的函数
        <code>
         inner
        </code>
        ，它能够接受任意数量和类型的参数并把它们传递给被包装的方法，这让我们能够用这个装饰器来装饰任何方法。
       </p>
       <blockquote>
        <p>
        </p>
        <!-- Crayon Syntax Highlighter v_2.7.2_beta -->
        <div class="crayon-syntax crayon-theme-classic crayon-font-monaco crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouseover" id="crayon-57686c2f9e959391295874" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
         <div class="crayon-toolbar" data-settings=" mouseover overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
          <span class="crayon-title">
          </span>
          <div class="crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">
           <div class="crayon-button crayon-nums-button" title="切换是否显示行编号">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-plain-button" title="纯文本显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-wrap-button" title="切换自动换行">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-expand-button" title="点击展开代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-copy-button" title="复制代码">
            <div class="crayon-button-icon">
            </div>
           </div>
           <div class="crayon-button crayon-popup-button" title="在新窗口中显示代码">
            <div class="crayon-button-icon">
            </div>
           </div>
          </div>
         </div>
         <div class="crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
         </div>
         <div class="crayon-plain-wrap">
          <textarea class="crayon-plain print-no" data-settings="dblclick" readonly="" style="-moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4; font-size: 12px !important; line-height: 15px !important;" wrap="soft">
           &amp;gt;&amp;gt;&amp;gt; @logger
... def foo1(x, y=1):
...     return x * y
&amp;gt;&amp;gt;&amp;gt; @logger
... def foo2():
...     return 2
&amp;gt;&amp;gt;&amp;gt; foo1(5, 4)
Arguments were: (5, 4), {}
20
&amp;gt;&amp;gt;&amp;gt; foo1(1)
Arguments were: (1,), {}
1
&amp;gt;&amp;gt;&amp;gt; foo2()
Arguments were: (), {}
2
          </textarea>
         </div>
         <div class="crayon-main" style="">
          <table class="crayon-table">
           <tbody>
            <tr class="crayon-row">
             <td class="crayon-nums " data-settings="show">
              <div class="crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
               <div class="crayon-num" data-line="crayon-57686c2f9e959391295874-1">
                1
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e959391295874-2">
                2
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e959391295874-3">
                3
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e959391295874-4">
                4
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e959391295874-5">
                5
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e959391295874-6">
                6
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e959391295874-7">
                7
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e959391295874-8">
                8
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e959391295874-9">
                9
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e959391295874-10">
                10
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e959391295874-11">
                11
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e959391295874-12">
                12
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e959391295874-13">
                13
               </div>
               <div class="crayon-num crayon-striped-num" data-line="crayon-57686c2f9e959391295874-14">
                14
               </div>
               <div class="crayon-num" data-line="crayon-57686c2f9e959391295874-15">
                15
               </div>
              </div>
             </td>
             <td class="crayon-code">
              <div class="crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
               <div class="crayon-line" id="crayon-57686c2f9e959391295874-1">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 @
                </span>
                <span class="crayon-i">
                 logger
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e959391295874-2">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 foo1
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-v">
                 x
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 y
                </span>
                <span class="crayon-o">
                 =
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e959391295874-3">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e ">
                 x *
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-v">
                 y
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e959391295874-4">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 @
                </span>
                <span class="crayon-i">
                 logger
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e959391295874-5">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 def
                </span>
                <span class="crayon-e">
                 foo2
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-o">
                 :
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e959391295874-6">
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-sy">
                 .
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-st">
                 return
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 2
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e959391295874-7">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 foo1
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-cn">
                 5
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 4
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e959391295874-8">
                <span class="crayon-e">
                 Arguments
                </span>
                <span class="crayon-v">
                 were
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-cn">
                 5
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-cn">
                 4
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e959391295874-9">
                <span class="crayon-cn">
                 20
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e959391295874-10">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 foo1
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e959391295874-11">
                <span class="crayon-e">
                 Arguments
                </span>
                <span class="crayon-v">
                 were
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-cn">
                 1
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e959391295874-12">
                <span class="crayon-cn">
                 1
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e959391295874-13">
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-o">
                 &amp;
                </span>
                <span class="crayon-v">
                 gt
                </span>
                <span class="crayon-sy">
                 ;
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-e">
                 foo2
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
               </div>
               <div class="crayon-line crayon-striped-line" id="crayon-57686c2f9e959391295874-14">
                <span class="crayon-e">
                 Arguments
                </span>
                <span class="crayon-v">
                 were
                </span>
                <span class="crayon-o">
                 :
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 (
                </span>
                <span class="crayon-sy">
                 )
                </span>
                <span class="crayon-sy">
                 ,
                </span>
                <span class="crayon-h">
                </span>
                <span class="crayon-sy">
                 {
                </span>
                <span class="crayon-sy">
                 }
                </span>
               </div>
               <div class="crayon-line" id="crayon-57686c2f9e959391295874-15">
                <span class="crayon-cn">
                 2
                </span>
               </div>
              </div>
             </td>
            </tr>
           </tbody>
          </table>
         </div>
        </div>
        <!-- [Format Time: 0.0203 seconds] -->
        <p>
        </p>
       </blockquote>
       <p>
        随便调用我们定义的哪个方法，相应的日志也会打印到输出窗口，和我们预期的一样。
       </p>
       <blockquote>
        <p>
         原文地址：
         <a href="https://dzone.com/articles/understanding-python" target="_blank">
          Understanding Python Decorators in 12 Easy Steps!
         </a>
        </p>
       </blockquote>
      </div>
      <div>
       <strong>
        注：转载文章均来自于公开网络，仅供学习使用，不会用于任何商业用途，如果侵犯到原作者的权益，请您与我们联系删除或者授权事宜，联系邮箱：contact@dataunion.org。转载数盟网站文章请注明原文章作者，否则产生的任何版权纠纷与数盟无关。
       </strong>
      </div>
      <!--content_text-->
      <div class="fenxian">
       <!-- JiaThis Button BEGIN -->
       <div class="jiathis_style_32x32">
        <p class="jiathis_button_weixin">
        </p>
        <p class="jiathis_button_tsina">
        </p>
        <p class="jiathis_button_qzone">
        </p>
        <p class="jiathis_button_cqq">
        </p>
        <p class="jiathis_button_tumblr">
        </p>
        <a class="jiathis jiathis_txt jtico jtico_jiathis" href="http://www.jiathis.com/share" target="_blank">
        </a>
        <p class="jiathis_counter_style">
        </p>
       </div>
       <!-- JiaThis Button END -->
      </div>
     </article>
     <!--content-->
     <!--相关文章-->
     <div class="xianguan">
      <div class="xianguantitle">
       相关文章！
      </div>
      <ul class="pic">
       <li>
        <a href="http://dataunion.org/20824.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/t018630756a7e263b33-300x165.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20824.html" rel="bookmark" title="如何判断一笔交易是否属于欺诈？你只是需要一点数据挖掘">
         如何判断一笔交易是否属于欺诈？你只是需要一点数据挖掘
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20820.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/1-300x200.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20820.html" rel="bookmark" title="人们对Python在企业级开发中的10大误解">
         人们对Python在企业级开发中的10大误解
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20811.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/t0133fcacae8523307b_副本-300x200.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20811.html" rel="bookmark" title="大神亲传：26条深度学习的金科玉律！">
         大神亲传：26条深度学习的金科玉律！
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/20808.html">
         <img src="http://dataunion.org/wp-content/uploads/2015/09/640.webp-11-300x137.jpg"/>
        </a>
        <a class="link" href="http://dataunion.org/20808.html" rel="bookmark" title="我们是如何在一张地图上表现86万个数据的">
         我们是如何在一张地图上表现86万个数据的
        </a>
       </li>
      </ul>
     </div>
     <!--相关文章-->
     <div class="comment" id="comments">
      <!-- You can start editing here. -->
      <!-- If comments are open, but there are no comments. -->
      <div class="title">
       期待你一针见血的评论，Come on！
      </div>
      <div id="respond">
       <p>
        不用想啦，马上
        <a href="http://dataunion.org/wp-login.php?redirect_to=http%3A%2F%2Fdataunion.org%2F19917.html">
         "登录"
        </a>
        发表自已的想法.
       </p>
      </div>
     </div>
     <!-- .nav-single -->
    </div>
    <!--Container End-->
    <aside id="sitebar">
     <div class="sitebar_list2">
      <div class="wptag">
       <span class="tagtitle">
        热门标签+
       </span>
       <div class="tagg">
        <ul class="menu" id="menu-%e5%8f%8b%e6%83%85%e9%93%be%e6%8e%a5">
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-1605" id="menu-item-1605">
          <a href="http://taidizh.com/">
           泰迪智慧
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20884" id="menu-item-20884">
          <a href="http://www.transwarp.cn/">
           星环科技
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-3538" id="menu-item-3538">
          <a href="http://datall.org/">
           珈和遥感
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-20888" id="menu-item-20888">
          <a href="http://www.chinahadoop.cn/">
           小象学院
          </a>
         </li>
        </ul>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <div class="textwidget">
       <div align="center">
        <a href="http://study.163.com/course/courseMain.htm?courseId=991022" target="_blank">
         <img src="http://dataunion.org/wp-content/uploads/2016/03/dv.jpg"/>
        </a>
       </div>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       文章分类
      </h4>
      <div class="tagcloud">
       <a class="tag-link-44" href="http://dataunion.org/category/industry/demo" style="font-size: 10.204724409449pt;" title="4个话题">
        Demo展示
       </a>
       <a class="tag-link-31" href="http://dataunion.org/category/experts" style="font-size: 15.826771653543pt;" title="52个话题">
        专家团队
       </a>
       <a class="tag-link-870" href="http://dataunion.org/category/tech/ai" style="font-size: 19.795275590551pt;" title="273个话题">
        人工智能
       </a>
       <a class="tag-link-488" href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f" style="font-size: 8pt;" title="1个话题">
        加入数盟
       </a>
       <a class="tag-link-869" href="http://dataunion.org/category/tech/viz" style="font-size: 17.204724409449pt;" title="93个话题">
        可视化
       </a>
       <a class="tag-link-30" href="http://dataunion.org/category/partners" style="font-size: 10.645669291339pt;" title="5个话题">
        合作伙伴
       </a>
       <a class="tag-link-889" href="http://dataunion.org/category/parterc" style="font-size: 11.582677165354pt;" title="8个话题">
        合作会议
       </a>
       <a class="tag-link-104" href="http://dataunion.org/category/books" style="font-size: 12.96062992126pt;" title="15个话题">
        图书
       </a>
       <a class="tag-link-220" href="http://dataunion.org/category/tech/base" style="font-size: 19.850393700787pt;" title="281个话题">
        基础架构
       </a>
       <a class="tag-link-219" href="http://dataunion.org/category/tech/analysis" style="font-size: 19.409448818898pt;" title="232个话题">
        数据分析
       </a>
       <a class="tag-link-887" href="http://dataunion.org/category/tech/dm" style="font-size: 13.291338582677pt;" title="17个话题">
        数据挖掘
       </a>
       <a class="tag-link-34" href="http://dataunion.org/category/tech" style="font-size: 20.732283464567pt;" title="404个话题">
        文章
       </a>
       <a class="tag-link-1" href="http://dataunion.org/category/uncategorized" style="font-size: 22pt;" title="693个话题">
        未分类
       </a>
       <a class="tag-link-4" href="http://dataunion.org/category/events" style="font-size: 14.503937007874pt;" title="29个话题">
        活动
       </a>
       <a class="tag-link-890" href="http://dataunion.org/category/tech/%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0" style="font-size: 10.204724409449pt;" title="4个话题">
        深度学习
       </a>
       <a class="tag-link-221" href="http://dataunion.org/category/tech/devl" style="font-size: 18.968503937008pt;" title="193个话题">
        编程语言
       </a>
       <a class="tag-link-888" href="http://dataunion.org/category/career" style="font-size: 15.661417322835pt;" title="48个话题">
        职业规划
       </a>
       <a class="tag-link-5" href="http://dataunion.org/category/jobs" style="font-size: 14.11811023622pt;" title="25个话题">
        职位
       </a>
       <a class="tag-link-871" href="http://dataunion.org/category/industry" style="font-size: 15.716535433071pt;" title="49个话题">
        行业
       </a>
       <a class="tag-link-613" href="http://dataunion.org/category/industry/case" style="font-size: 16.984251968504pt;" title="84个话题">
        行业应用
       </a>
       <a class="tag-link-885" href="http://dataunion.org/category/industry/news" style="font-size: 17.425196850394pt;" title="102个话题">
        行业资讯
       </a>
       <a class="tag-link-10" href="http://dataunion.org/category/training" style="font-size: 14.228346456693pt;" title="26个话题">
        课程
       </a>
       <a class="tag-link-16" href="http://dataunion.org/category/sources" style="font-size: 15.661417322835pt;" title="48个话题">
        资源
       </a>
      </div>
     </div>
     <div class="sitebar_list">
      <h4 class="sitebar_title">
       功能
      </h4>
      <ul>
       <li>
        <a href="http://dataunion.org/wp-login.php?action=register">
         注册
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/wp-login.php">
         登录
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/feed">
         文章
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="http://dataunion.org/comments/feed">
         评论
         <abbr title="Really Simple Syndication">
          RSS
         </abbr>
        </a>
       </li>
       <li>
        <a href="https://cn.wordpress.org/" title="基于WordPress，一个优美、先进的个人信息发布平台。">
         WordPress.org
        </a>
       </li>
      </ul>
     </div>
    </aside>
    <div class="clear">
    </div>
   </div>
   <!--main-->
   ﻿
   <footer id="dibu">
    <div class="about">
     <div class="right">
      <ul class="menu" id="menu-%e5%ba%95%e9%83%a8%e8%8f%9c%e5%8d%95">
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-18024" id="menu-item-18024">
        <a href="http://dataunion.org/category/partners">
         合作伙伴
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20881" id="menu-item-20881">
        <a href="http://dataunion.org/contribute">
         文章投稿
        </a>
       </li>
       <li class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-20872" id="menu-item-20872">
        <a href="http://dataunion.org/category/%e5%8a%a0%e5%85%a5%e6%95%b0%e7%9b%9f">
         加入数盟
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-22441" id="menu-item-22441">
        <a href="http://dataunion.org/f-links">
         友情链接
        </a>
       </li>
       <li class="menu-item menu-item-type-post_type menu-item-object-page menu-item-20874" id="menu-item-20874">
        <a href="http://dataunion.org/aboutus">
         关于数盟
        </a>
       </li>
      </ul>
      <p class="banquan">
       数盟社区        ，
        做最棒的数据科学社区
      </p>
     </div>
     <div class="left">
      <ul class="bottomlist">
       <li>
        <a href="http://weibo.com/DataScientistUnion  " target="_blank" 　title="">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weibo.png"/>
        </a>
       </li>
       <li>
        <a class="cd-popup-trigger" href="http://dataunion.org/19917.html#0">
         <img src="http://dataunion.org/wp-content/themes/yzipi/images/weixin.png"/>
        </a>
       </li>
      </ul>
      <div class="cd-popup">
       <div class="cd-popup-container">
        <h1>
         扫描二维码,加微信公众号
        </h1>
        <img src="http://dataunion.org/wp-content/themes/yzipi/images/2014-12-06-1515289049.png"/>
        <a class="cd-popup-close" href="http://dataunion.org/19917.html">
        </a>
       </div>
       <!-- cd-popup-container -->
      </div>
      <!-- cd-popup -->
     </div>
    </div>
    <!--about-->
    <div class="bottom">
     <a href="http://dataunion.org/">
      数盟社区
     </a>
     <a href="http://www.miitbeian.gov.cn/" rel="external nofollow" target="_blank">
      京ICP备14026740号
     </a>
     联系我们：
     <a href="mailto:contact@dataunion.org" target="_blank">
      contact@dataunion.org
     </a>
     <div class="tongji">
     </div>
     <!--bottom-->
     <div class="scroll" id="scroll" style="display:none;">
      ︿
     </div>
    </div>
   </footer>
   <!--dibu-->
  </div>
 </body>
</html>